package com.ruoyi.business.controller;

import com.ruoyi.business.domain.FileExternalUnitsForm;
import com.ruoyi.business.service.IFileExternalUnitsFormService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 外单位转入Controller
 *
 * @author ruoyi
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/business/form")
public class FileExternalUnitsFormController extends BaseController
{
    @Autowired
    private IFileExternalUnitsFormService fileExternalUnitsFormService;

    /**
     * 查询外单位转入列表
     */
    @PreAuthorize("@ss.hasPermi('business:form:list')")
    @GetMapping("/list")
    public TableDataInfo<FileExternalUnitsForm> list(FileExternalUnitsForm fileExternalUnitsForm, PageQuery pageQuery)
    {
        return fileExternalUnitsFormService.selectPageFileExternalUnitsFormList(fileExternalUnitsForm, pageQuery);
//        startPage();
//        List<FileExternalUnitsForm> list = fileExternalUnitsFormService.selectFileExternalUnitsFormList(fileExternalUnitsForm);
//        return getDataTable(list);
    }

    /**
     * 导出外单位转入列表
     */
    @PreAuthorize("@ss.hasPermi('business:form:export')")
    @Log(title = "外单位转入", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(FileExternalUnitsForm fileExternalUnitsForm, HttpServletResponse response)
    {
        List<FileExternalUnitsForm> list = fileExternalUnitsFormService.selectFileExternalUnitsFormList(fileExternalUnitsForm);
        ExcelUtil.exportExcel(list, "外单位转入", FileExternalUnitsForm.class, response);
//        ExcelUtil<FileExternalUnitsForm> util = new ExcelUtil<FileExternalUnitsForm>(FileExternalUnitsForm.class);
//        return util.exportExcel(list, "form");
    }

    /**
     * 获取外单位转入详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:form:query')")
    @GetMapping(value = "/{id}")
    public R<FileExternalUnitsForm> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(fileExternalUnitsFormService.selectFileExternalUnitsFormById(id));
    }

    /**
     * 新增外单位转入
     */
    @PreAuthorize("@ss.hasPermi('business:form:add')")
    @Log(title = "外单位转入", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody FileExternalUnitsForm fileExternalUnitsForm)
    {
        return toAjax(fileExternalUnitsFormService.insertFileExternalUnitsForm(fileExternalUnitsForm));
    }

    /**
     * 修改外单位转入
     */
    @PreAuthorize("@ss.hasPermi('business:form:edit')")
    @Log(title = "外单位转入", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody FileExternalUnitsForm fileExternalUnitsForm)
    {
        return toAjax(fileExternalUnitsFormService.updateFileExternalUnitsForm(fileExternalUnitsForm));
    }

    /**
     * 删除外单位转入
     */
    @PreAuthorize("@ss.hasPermi('business:form:remove')")
    @Log(title = "外单位转入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return toAjax(fileExternalUnitsFormService.deleteFileExternalUnitsFormByIds(ids));
    }
}
